package cn.iocoder.yudao.module.trade.controller.admin.lifecircle;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.trade.controller.admin.lifecircle.vo.LifeCircleStoreTypePageReqVO;
import cn.iocoder.yudao.module.trade.dal.dataobject.lifecircle.LifeCircleStoreTypeDO;
import cn.iocoder.yudao.module.trade.service.lifecircle.LifeCircleStoreTypeService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Tag(name = "管理后台 - 生活圈管理-店铺分类管理")
@RestController
@RequestMapping("/trade/life-circle/store-type")
@Validated
public class LifeCircleStoreTypeController {

    @Resource
    private LifeCircleStoreTypeService lifeCircleStoreTypeService;

    @PostMapping("/create")
    @Operation(summary = "创建店铺分类")
    @PreAuthorize("@ss.hasPermission('trade:life-circle:store:create')")
    public CommonResult<Long> createLifeCircleStore(@RequestBody LifeCircleStoreTypeDO lifeCircleStoreType) {
        return success(lifeCircleStoreTypeService.createLifeCircleStore(lifeCircleStoreType));
    }

    @PutMapping("/update")
    @Operation(summary = "更新店铺分类")
    @PreAuthorize("@ss.hasPermission('trade:life-circle:store:update')")
    public CommonResult<Boolean> updateLifeCircleStore(@RequestBody LifeCircleStoreTypeDO lifeCircleStoreType) {
        lifeCircleStoreTypeService.updateLifeCircleStore(lifeCircleStoreType);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除店铺分类")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('trade:life-circle:store:delete')")
    public CommonResult<Boolean> deleteLifeCircleStore(@RequestParam("id") Long id) {
        lifeCircleStoreTypeService.deleteLifeCircleStore(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得店铺分类")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('trade:life-circle:store:query')")
    public CommonResult<LifeCircleStoreTypeDO> getLifeCircleStore(@RequestParam("id") Long id) {
        LifeCircleStoreTypeDO lifeCircleStoreType = lifeCircleStoreTypeService.getLifeCircleStore(id);
        return success(lifeCircleStoreType);
    }


    @GetMapping("/page")
    @Operation(summary = "获得店铺分类分页")
    @PreAuthorize("@ss.hasPermission('trade:life-circle:store:query')")
    public CommonResult<PageResult<LifeCircleStoreTypeDO>> getLifeCircleStorePage(LifeCircleStoreTypePageReqVO lifeCircleStoreType) {
        PageResult<LifeCircleStoreTypeDO> pageResult = lifeCircleStoreTypeService.getLifeCircleStorePage(lifeCircleStoreType);
        return success(pageResult);
    }

}